package Study.demo12;

import com.mysql.cj.xdevapi.PreparableStatement;

import java.sql.*;

public class jdbcPrepares {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/aaa","root","");
            //获取statemen对象，conection接口中的对象用于执行静态的SQL语句
            //Statement statement=conn.createStatement();
            //parastament用于执行动态态的变量，可改变插入的值
            /*PreparedStatement pstmen=conn.prepareStatement("update  Student set password=? where id=?");
            pstmen.setString(1,"123456");
            pstmen.setInt(2,26);
            pstmen.executeUpdate();
            pstmen.close();*/
            PreparedStatement pst=conn.prepareStatement("select * from Student");
            ResultSet rs=pst.executeQuery();
            while(rs.next()){
                System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
            }

       //PreparedStatement pstmot2=conn.prepareStatement("delete from Student where id=?");

            /*PreparedStatement pstmt=  conn.prepareStatement("insert into Student(id,name,password) values (?,?,?)");
           开头第一个表示索引
            pstmt.setString(1,"12");
           pstmt.setString(2,"fendar");
            pstmt.setString(3,"125846");*/

            //pstmot2.setString(1,"12");
            //执行更新操作
           // pstmt.executeUpdate();
           // pstmot2.execute();
            //pstmot2.close();
           // pstmt.close();
            conn.close();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
